package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ArticleService;
import com.heima.common.constants.HotArticleConstants;
import com.heima.model.mess.ArticleVisitStreamMess;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author brianxia
 * @version 1.0
 * @date 2022-09-27 14:49
 */
@Component
@Slf4j
public class HotArticleIncrHandleListener {

    @Autowired
    private ArticleService articleService;


    @KafkaListener(topics = {HotArticleConstants.HOT_ARTICLE_INCR_HANDLE_TOPIC})
    public void stream(String msg){
        if(StringUtils.isBlank(msg)){
            return;
        }

        ArticleVisitStreamMess mess = JSON.parseObject(msg,ArticleVisitStreamMess.class);

        articleService.hotArticleHandle(mess);
    }
}
